﻿using System;
namespace ORS.OrderRobot.IOC
{
	/// <summary>
	/// 全局provider静态类
	/// </summary>
	public class ServiceProviderAccessor
	{
        private static IServiceProvider? _provider;
        /// <summary>
        /// 设置provider
        /// </summary>
        /// <param name="provider"></param>
        public static void Set(IServiceProvider provider)
        {
            _provider = provider;
        }
        /// <summary>
        ///  获取全局provider
        /// </summary>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public static IServiceProvider Get()
        {
            if (_provider == null)
                throw new InvalidOperationException("全局IServiceProvider尚未设置！");
            return _provider;
        }
    }
}

